<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css" />
    <link rel="stylesheet" href="../../../static/css/bootstrap-theme.min.css" />
    <script src="../../../static/js/jquery-3.3.1.min.js"></script>

</head>
<body>
<div class="layui-card">
    <div class="layui-card-header">
        <h2>学生成绩编辑</h2>
    </div>
    <form class="layui-form" id="StudentScoreForm">
        <div class="layui-form-item">
            <label class="layui-form-label">课程ID</label>
            <div class="layui-input-inline">
                <input type="text" name="courseId" id="courseId" required lay-verify="required"  placeholder="不可编辑" readonly="" autocomplete="off"
                       class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">课程名称</label>
            <div class="layui-input-inline">
                <input type="text" name="courseName" id="courseName" required lay-verify="required"  placeholder="不可编辑" readonly="" autocomplete="off"
                       class="layui-input">
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">学生ID</label>
            <div class="layui-input-inline">
                <input type="text" name="studentId" id="studentId" required lay-verify="required"  placeholder="不可编辑" readonly="" autocomplete="off"
                       class="layui-input">
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">学生名字</label>
            <div class="layui-input-inline">
                <input type="text" name="studentName" id="studentName" required lay-verify="required"  placeholder="不可编辑" readonly="" autocomplete="off"
                       class="layui-input">
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">课程分数</label>
            <div class="layui-input-inline">
                <input type="text" name="score"  id="score" required lay-verify="required" placeholder="请输入学生分数"  autocomplete="off"
                       class="layui-input">
            </div>

        </div>

        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">教师ID</label>
            <div class="layui-input-inline">
                <input type="text" name="teacherId"  id="teacherId" value="${sessionScope.teacher.teacherId}" required lay-verify="required" placeholder="请输入学生分数"  autocomplete="off"
                       class="layui-input">
            </div>

        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn updateStudentScore" lay-submit lay-filter="updateStudentScore">立即提交</button>
            </div>
        </div>

    </form>
</div>
<script src="../../../static/layui/layui.all.js"></script>
<script>
    //Demo

    layui.use('form', function() {
        var form = layui.form;
        var layer = layui.layer;

        $(document).ready(function(){

            $(function () {
                //从父层获取值，json是父层的全局js变量。eval是将该string类型的json串变为标准的json串
                var parent_json = eval('('+parent.json+')');
                console.log(parent_json);
                var studentId = parent_json.studentId;
                var studentName = parent_json.studentName;
                var score = parent_json.score;
                var courseId = parent_json.courseId;
                var courseName = parent_json.courseName;

                $('#studentId').val(studentId);
                $('#studentName').val(studentName);
                $('#score').val(score);
                $('#courseId').val(courseId);
                $('#courseName').val(courseName);
            });

            $('.updateStudentScore').click(function(){
                // 添加课程

                $.post(
                    "${pageContext.request.contextPath}/updateStudentScore",
                    $('#StudentScoreForm').serialize(),
                    function (data) {
                        if(data==0){
                            layer.msg("修改失败~",{icon:"5"});
                        }else if(data>0) {
                            layer.msg("修改" + studentName + "的成绩成功~", {icon: "6"});
                            parent.location.reload(); // 父页面刷新
                        }
                    }

                );
            });

        });

    });
</script>
</body>
</html>
